/*
* Copyright (C) 1997-2001 Id Software, Inc.
* 
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
* 
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE.
* 
* See the GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place - Suite 330, Boston, MA 02111-1307, USA.
*  
*/

// Created on 31.10.2003 by RST.
// $Id: game_locals_t.java,v 1.7 2004/09/22 19:22:06 salomo Exp $
using System;
using Defines = Suake2.UI.Defines;
using Com = Suake2.UI.qcommon.Com;
using Lib = Suake2.UI.util.Lib;
using QuakeFile = Suake2.UI.util.QuakeFile;
//UPGRADE_TODO: The type 'java.nio.ByteBuffer' could not be found. If it was not included in the conversion, there may be compiler issues. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1262'"
using ByteBuffer = java.nio.ByteBuffer;
namespace Suake2.UI.game
{
	
	public class game_locals_t
	{
		public game_locals_t()
		{
			InitBlock();
		}
		private void  InitBlock()
		{
			clients = new gclient_t[Defines.MAX_CLIENTS];
		}
		//
		//	this structure is left intact through an entire game
		//	it should be initialized at dll load time, and read/written to
		//	the server.ssv file for savegames
		//
		
		public System.String helpmessage1 = "";
		
		public System.String helpmessage2 = "";
		
		public int helpchanged; // flash F1 icon if non 0, play sound
		
		// and increment only if 1, 2, or 3
		
		//UPGRADE_NOTE: The initialization of  'clients' was moved to method 'InitBlock'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1005'"
		public gclient_t[] clients;
		
		// can't store spawnpoint in level, because
		// it would get overwritten by the savegame restore
		public System.String spawnpoint = ""; // needed for coop respawns
		
		// store latched cvars here that we want to get at often
		public int maxclients;
		
		public int maxentities;
		
		// cross level triggers
		public int serverflags;
		
		// items
		public int num_items;
		
		public bool autosaved;
		
		/// <summary>Reads the game locals from a file. </summary>
		public virtual void  load(QuakeFile f)
		{
			System.String date = f.readString();
			
			helpmessage1 = f.readString();
			helpmessage2 = f.readString();
			
			System.IO.BinaryReader temp_BinaryReader;
			temp_BinaryReader = new System.IO.BinaryReader(f);
			temp_BinaryReader.BaseStream.Position = f.Position;
			helpchanged = temp_BinaryReader.ReadInt32();
			// gclient_t*
			
			spawnpoint = f.readString();
			System.IO.BinaryReader temp_BinaryReader2;
			temp_BinaryReader2 = new System.IO.BinaryReader(f);
			temp_BinaryReader2.BaseStream.Position = f.Position;
			maxclients = temp_BinaryReader2.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader3;
			temp_BinaryReader3 = new System.IO.BinaryReader(f);
			temp_BinaryReader3.BaseStream.Position = f.Position;
			maxentities = temp_BinaryReader3.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader4;
			temp_BinaryReader4 = new System.IO.BinaryReader(f);
			temp_BinaryReader4.BaseStream.Position = f.Position;
			serverflags = temp_BinaryReader4.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader5;
			temp_BinaryReader5 = new System.IO.BinaryReader(f);
			temp_BinaryReader5.BaseStream.Position = f.Position;
			num_items = temp_BinaryReader5.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader6;
			temp_BinaryReader6 = new System.IO.BinaryReader(f);
			temp_BinaryReader6.BaseStream.Position = f.Position;
			autosaved = temp_BinaryReader6.ReadInt32() != 0;
			
			// rst's checker :-)
			System.IO.BinaryReader temp_BinaryReader7;
			temp_BinaryReader7 = new System.IO.BinaryReader(f);
			temp_BinaryReader7.BaseStream.Position = f.Position;
			if (temp_BinaryReader7.ReadInt32() != 1928)
				Com.DPrintf("error in loading game_locals, 1928\n");
		}
		
		/// <summary>Writes the game locals to a file. </summary>
		public virtual void  write(QuakeFile f)
		{
			//UPGRADE_TODO: Method 'java.util.Date.toString' was converted to 'System.DateTime.ToString' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilDatetoString'"
			f.writeString(System.DateTime.Now.ToString("r"));
			
			f.writeString(helpmessage1);
			f.writeString(helpmessage2);
			
			System.IO.BinaryWriter temp_BinaryWriter;
			temp_BinaryWriter = new System.IO.BinaryWriter(f);
			temp_BinaryWriter.Write((System.Int32) helpchanged);
			// gclient_t*
			
			f.writeString(spawnpoint);
			System.IO.BinaryWriter temp_BinaryWriter2;
			temp_BinaryWriter2 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter2.Write((System.Int32) maxclients);
			System.IO.BinaryWriter temp_BinaryWriter3;
			temp_BinaryWriter3 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter3.Write((System.Int32) maxentities);
			System.IO.BinaryWriter temp_BinaryWriter4;
			temp_BinaryWriter4 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter4.Write((System.Int32) serverflags);
			System.IO.BinaryWriter temp_BinaryWriter5;
			temp_BinaryWriter5 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter5.Write((System.Int32) num_items);
			System.IO.BinaryWriter temp_BinaryWriter6;
			temp_BinaryWriter6 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter6.Write((System.Int32) (autosaved?1:0));
			// rst's checker :-)
			System.IO.BinaryWriter temp_BinaryWriter7;
			temp_BinaryWriter7 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter7.Write((System.Int32) 1928);
		}
	}
}